package com.bocai.dahuatech.ui.activity;

import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;
import android.view.View;
import android.widget.LinearLayout;

import com.bocai.dahuatech.R;
import com.bocai.dahuatech.base.BaseActivity;
import com.bocai.dahuatech.ui.frag.News_Companynews_Fragment;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 *资讯列表
 */
public class NewsListActivity extends BaseActivity {
    @Bind(R.id.order_tab)
    TabLayout mTabLayout;
    @Bind(R.id.order_vp)
    ViewPager viewPager;
    @Bind(R.id.ll_myorder_nocontent)
    LinearLayout llNoContent;
    String news;
    String  policy;
    @Override
    protected int contentView() {
        return R.layout.activity_my_order_list;
    }

    @Override
    protected void initView() {
        ButterKnife.bind(this);
        initToolbar(R.string.news);
        news=getResources().getString(R.string.newstypenews);
        policy=getResources().getString(R.string.newstypenpolicy);
        llNoContent.setVisibility(View.GONE);
        viewPager.setAdapter(new Adapter(getSupportFragmentManager()));
        mTabLayout.setupWithViewPager(viewPager);
        viewPager.setOffscreenPageLimit(2);
        mTabLayout.setTabMode(TabLayout.MODE_FIXED);
        initEvent();
    }

    @Override
    protected void initEvent() {
        super.initEvent();
    }

    class Adapter extends FragmentPagerAdapter {
        private final Fragment[] fragments = new Fragment[2];
        private final String [] titles= {news,policy};
        int[] types={12,14};
        public Adapter(FragmentManager fm) {
            super(fm);
        }


        @Override
        public Fragment getItem(int position) {
            Fragment fragment = fragments[position];
            if (fragment == null) {
                fragment = new News_Companynews_Fragment(types[position]);
                fragments[position] = fragment;
            }
            return fragment;
        }

        @Override
        public int getCount() {
            return 2;
        }

        @Override
        public CharSequence getPageTitle(int position) {

            return titles[position];
        }
    }
}
